package com.hong.config.parse;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;
import java.util.Properties;

/**
 * @Author HQT
 * @Date 2022/7/15 17:31
 */
@Slf4j
public class PropertiesParser implements Parser {
    @Override
    public Map<Object,Object> parse(String url) {
        InputStream in = PropertiesParser.class.getClassLoader().getResourceAsStream(url);
        Properties config = new Properties();
        try {
            config.load(in);
            log.info("load profile {} success",url);
        } catch (IOException e) {
            log.error("read properties file error");
        }
        HashMap<Object, Object> properties = new HashMap<>();
        for (Map.Entry<Object, Object> entry : config.entrySet()) {
            //只拿自己需要的值
            if(((String)entry.getKey()).startsWith("qrpc")){
                properties.put(entry.getKey(),entry.getValue());
            }
        }
        return properties;
    }

}
